﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
namespace NJL.Web.Visitor
{
    public partial class FriendList : BasePageVisitor
    {
        NJL.BLL.NJL_MYFRIEND bll = new BLL.NJL_MYFRIEND();
        NJL.BLL.NJL_MYFRIEND bllMyFriend = new BLL.NJL_MYFRIEND();
        NJL.BLL.NJL_USER bllUser = new BLL.NJL_USER();
        NJL.Model.NJL_USER modelUser;
        NJL.BLL.NJL_MYFRIEND bllFriend = new BLL.NJL_MYFRIEND();
        NJL.BLL.NJL_NEWS bllNews = new BLL.NJL_NEWS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {          
                modelUser = bllUser.GetModel(Request.QueryString["uid"].ToString());
                Page.Title = "关注-" + modelUser.USER_NAME + "的乡间小屋";
                lituserName.Text = modelUser.USER_NAME;
                litName1.Text = modelUser.USER_NAME;
                DataSet ds = bllMyFriend.GetList("NJL_MYFRIEND.NJL_USER_ID=" + Request.QueryString["uid"]);
                litFrientCount.Text = ds.Tables[0].Rows.Count.ToString();
                string[] param = { "uid" };
                if (ds.Tables[0].Rows.Count > 10)
                {
                    pager.InnerHtml = Royalsoft.Common.Pager.GetPageNum(ds, rptTravel, 20, param, "/wanjia/");
                }
                else
                {
                    rptTravel.DataSource = ds;
                    rptTravel.DataBind();
                }
                #region 新闻分类
                NJL.BLL.NJL_CS_NEWS_TYPE bllNewsType = new BLL.NJL_CS_NEWS_TYPE();
                ds = bllNewsType.GetList("TYPE_CODE<100");
                newsType.DataSource = ds;
                newsType.DataBind();
                #endregion
   
                litAllNews.Text = bllNews.GetList("NJL_PERSON_ID='" + Request.QueryString["uid"] + "'").Tables[0].Rows.Count.ToString();
            }
        }

        /// <summary>
        /// 加载页面SEO
        /// </summary>
        private void LoadPageSEO()
        {
            Page.Title = modelUser.USER_NAME + "的关注";

            //HtmlMeta myMeta = new HtmlMeta();
            //myMeta.Name = "Keywords";
            //myMeta.Content = bllPerson.SEO_KEYWORDS;
            //this.Header.Controls.Add(myMeta);

            //HtmlMeta myMeta1 = new HtmlMeta();
            //myMeta1.Name = "Description";
            //myMeta1.Content = bllPerson.SEO_DESCRIPTION;
            //this.Header.Controls.Add(myMeta1);
        }

        protected void rptTravel_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Literal lit = e.Item.FindControl("litAttention") as Literal;
                DataRowView drv = (DataRowView)e.Item.DataItem;
                string id = drv["ID1"].ToString();
                if (UserId != "" && UserName != "")
                {
                    DataSet dsFriend = bllFriend.GetList("NJL_MYFRIEND.FRIEND_USER_ID=" + id + " and NJL_MYFRIEND.NJL_USER_ID=" + UserId);
                    if (UserId.Equals(id) && UserType == "2")
                    {
                        lit.Text = "";
                    }
                    else if (!UserId.Equals(id) && UserType == "2")
                    {
                        if (dsFriend.Tables[0].Rows.Count > 0)
                        {
                            lit.Text = "<a href=javascript:DeleteUser('" + id + "')>-&nbsp;取消关注</a>";
                        }
                        else
                        {
                            lit.Text = "<a href=javascript:AddUser('" + id + "')>+&nbsp;添加关注</a>";
                        }
                    }
                }
                else
                {
                    lit.Text = "<a href=javascript:AddUser('" + id + "')>+&nbsp;添加关注</a>";
                }

            }
        }
        DataSet ds;
        protected void newsType_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView grv = (DataRowView)e.Item.DataItem;
                string typeCode = grv["TYPE_CODE"].ToString();
                Literal lit = e.Item.FindControl("litNewsCount") as Literal;
                ds = bllNews.GetList("NJL_PERSON_ID='" + Request.QueryString["uid"] + "' and TYPE_CODE='" + typeCode + "'");
                lit.Text = ds.Tables[0].Rows.Count.ToString();
            }
        }
    }
}